package com.xgkj.diyiketang.fragment;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TabHost;

import com.xgkj.diyiketang.activity.MainActivity;
import com.xgkj.diyiketang.R;

/**
 * Created by XCKJ_Paladowow on 2016/3/14.
 */
public class ZhuBoFragment extends BaseFragment{
    private Context mContext;
    private TabHost tabHost;
    private View rootView;

    @Override
    protected int getContentViewId() {
        return 0;
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
//        View view = inflater.inflate(R.layout.zhubo_fragment,null);
        if (rootView == null) {
            rootView = inflater.inflate(R.layout.zhubo_fragment, null);
            mContext = getActivity();
            tabHost = (TabHost) rootView.findViewById(android.R.id.tabhost);
            tabHost.setup();

            tabHost.addTab(tabHost.newTabSpec("A")
                    .setIndicator(getTabView(R.layout.tab_1))
                    .setContent(R.id.fg_01));

            tabHost.addTab(tabHost.newTabSpec("B")
                    .setIndicator(getTabView(R.layout.tab_2))
                    .setContent(R.id.fg_02));
            tabHost.setCurrentTabByTag("A");
        }
        ViewGroup parent = (ViewGroup) rootView.getParent();
        if (parent != null){
            parent.removeView(rootView);
        }

//        tabHost.addTab(tabHost.newTabSpec("C")
//                .setIndicator(getTabView(R.layout.tab_3))
//                .setContent(R.id.fg_03));
//        Bundle b = getArguments();
//        boolean isXyb = b.getBoolean("goxyb");
//        boolean isXyb = ((MainActivity)getActivity()).isGoXyb();
//        if (isXyb) {
//            tabHost.setCurrentTabByTag("C");
//            ((MainActivity)getActivity()).setGoXyb(false);
//        }
        return rootView;
    }

    @Override
    public void onHiddenChanged(boolean hidden) {
        super.onHiddenChanged(hidden);
        if(!hidden&&isAdded()){
//            boolean isXyb = ((MainActivity)getActivity()).isGoXyb();
//            if (isXyb) {
//                tabHost.setCurrentTabByTag("C");
//                ((MainActivity)getActivity()).setGoXyb(false);
//            }
        }

    }

    private View getTabView(int layoutid) {
        // TODO Auto-generated method stub
        View view = LayoutInflater.from(mContext).inflate(layoutid, null);
        return view;
    }

}
